VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form FRMmain 
   AutoRedraw      =   -1  'True
   BackColor       =   &H00E0E0E0&
   Caption         =   "Access Search"
   ClientHeight    =   7695
   ClientLeft      =   3600
   ClientTop       =   2460
   ClientWidth     =   8895
   BeginProperty Font 
      Name            =   "Verdana"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "mainFRM.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   513
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   593
   Begin VB.OptionButton optionExactMatch 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Exact"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   960
      TabIndex        =   5
      Top             =   1440
      Width           =   855
   End
   Begin VB.OptionButton optionStartsWith 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Starts With"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   1920
      TabIndex        =   4
      Top             =   1440
      Width           =   1335
   End
   Begin VB.OptionButton optionEndsWith 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Ends With"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3360
      TabIndex        =   3
      Top             =   1440
      Width           =   1215
   End
   Begin VB.OptionButton optionAnyMatch 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Any"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   1440
      Width           =   855
   End
   Begin VB.OptionButton optionWildCard 
      BackColor       =   &H00E0E0E0&
      Caption         =   "*"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   4680
      TabIndex        =   2
      Top             =   1440
      Value           =   -1  'True
      Width           =   375
   End
   Begin VB.ListBox LISTfields 
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1620
      ItemData        =   "mainFRM.frx":0442
      Left            =   5640
      List            =   "mainFRM.frx":0449
      Sorted          =   -1  'True
      TabIndex        =   6
      Top             =   120
      Width           =   3135
   End
   Begin VB.ComboBox LISTtables 
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      ItemData        =   "mainFRM.frx":0459
      Left            =   1440
      List            =   "mainFRM.frx":045B
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   120
      Width           =   3615
   End
   Begin VB.TextBox TXTsearch 
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   1440
      MaxLength       =   500
      TabIndex        =   1
      Top             =   555
      Width           =   3615
   End
   Begin VB.CommandButton searchButt 
      BackColor       =   &H00E0E0E0&
      Caption         =   "search"
      Default         =   -1  'True
      Height          =   375
      Left            =   7200
      TabIndex        =   8
      Top             =   1845
      Width           =   1575
   End
   Begin MSComDlg.CommonDialog CommonDialog 
      Left            =   1920
      Top             =   7080
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      DialogTitle     =   "Open Database"
      Filter          =   "All Files | *.*"
   End
   Begin MSDataGridLib.DataGrid DataGrid 
      Bindings        =   "mainFRM.frx":045D
      CausesValidation=   0   'False
      Height          =   4935
      Left            =   120
      TabIndex        =   13
      Top             =   2280
      Width           =   8655
      _ExtentX        =   15266
      _ExtentY        =   8705
      _Version        =   393216
      AllowUpdate     =   -1  'True
      AllowArrows     =   -1  'True
      BackColor       =   16777215
      HeadLines       =   1
      RowHeight       =   15
      AllowDelete     =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1037
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1037
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Label LBLresultsCount 
      BackStyle       =   0  'Transparent
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   1680
      TabIndex        =   16
      Top             =   2070
      Width           =   1695
   End
   Begin VB.Label LBLremoteUpdateSuccess 
      BackColor       =   &H00E0E0E0&
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000C0&
      Height          =   255
      Left            =   120
      TabIndex        =   15
      Top             =   7320
      Width           =   8055
   End
   Begin VB.Label Label5 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Match"
      Height          =   255
      Left            =   120
      TabIndex        =   14
      Top             =   1200
      Width           =   1455
   End
   Begin VB.Line Line1 
      BorderColor     =   &H80000003&
      X1              =   0
      X2              =   549
      Y1              =   0
      Y2              =   0
   End
   Begin VB.Label Label3 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Field"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5160
      TabIndex        =   12
      Top             =   120
      Width           =   495
   End
   Begin VB.Label Label4 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Table"
      Height          =   300
      Left            =   120
      TabIndex        =   11
      Top             =   195
      Width           =   1215
   End
   Begin VB.Label Label2 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Search For :"
      Height          =   285
      Left            =   120
      TabIndex        =   10
      Top             =   615
      Width           =   1455
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "Search Results"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   120
      TabIndex        =   9
      Top             =   2070
      Width           =   1455
   End
   Begin VB.Menu fileMenu 
      Caption         =   "&File"
      Begin VB.Menu fileOpen 
         Caption         =   "&Open"
         Shortcut        =   ^O
      End
      Begin VB.Menu fileMenuHR1 
         Caption         =   "-"
      End
      Begin VB.Menu fileImport 
         Caption         =   "&Import"
         Shortcut        =   ^I
      End
      Begin VB.Menu fileExportToExcel 
         Caption         =   "&Export DataBase"
         Shortcut        =   ^X
      End
      Begin VB.Menu fileMenuHR2 
         Caption         =   "-"
      End
      Begin VB.Menu filePrint 
         Caption         =   "&Print"
         Shortcut        =   ^P
      End
      Begin VB.Menu fileMenuHR3 
         Caption         =   "-"
      End
      Begin VB.Menu fileQuit 
         Caption         =   "&Quit"
         Shortcut        =   ^Q
      End
   End
   Begin VB.Menu editMenu 
      Caption         =   "&Edit"
      Begin VB.Menu editCopyRow 
         Caption         =   "&Copy Row"
         Shortcut        =   ^C
      End
      Begin VB.Menu editAddRow 
         Caption         =   "&Add Row"
         Shortcut        =   ^A
      End
      Begin VB.Menu editDeleteRow 
         Caption         =   "&Delete Row"
         Shortcut        =   ^D
      End
      Begin VB.Menu editMenuHR1 
         Caption         =   "-"
      End
      Begin VB.Menu editUpdateRow 
         Caption         =   "&Update Row"
         Enabled         =   0   'False
      End
   End
   Begin VB.Menu toolsMenu 
      Caption         =   "&Tools"
      Begin VB.Menu toolsCalculator 
         Caption         =   "&Calculator"
         Shortcut        =   ^L
      End
      Begin VB.Menu ToolSendMail 
         Caption         =   "&Send Request Mail"
         Shortcut        =   ^M
      End
      Begin VB.Menu toolsPreferences 
         Caption         =   "&Preferences"
         Shortcut        =   ^R
      End
   End
   Begin VB.Menu Web 
      Caption         =   "&Web"
      Begin VB.Menu WebUpdateAllRecords 
         Caption         =   "&Update Remote Database"
         Shortcut        =   ^S
      End
      Begin VB.Menu WebSeperator1 
         Caption         =   "-"
      End
      Begin VB.Menu WebUpdateLater 
         Caption         =   "&Save Update To File"
      End
      Begin VB.Menu WebUpdateFromFile 
         Caption         =   "Update &From File"
      End
      Begin VB.Menu WebSeperator2 
         Caption         =   "-"
      End
      Begin VB.Menu WebDeleteSavedUpdate 
         Caption         =   "&Delete Current Saved Records"
      End
   End
   Begin VB.Menu helpmenu 
      Caption         =   "&Help"
      Begin VB.Menu helpMenuAbout 
         Caption         =   "&About"
      End
   End
End
Attribute VB_Name = "FRMmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public aColumnWidths As Variant

Public _
    bRemoteSaved As Boolean

Public _
    uniqueIDindex As Integer

Private _
    doRemoteUpdate As Boolean, _
    boolAddrow As Boolean

Dim _
    matchPhrase As String, _
    matchCase As String, _
    strColumnWidths

Dim _
    Ymouse As Integer, _
    Xmouse As Integer

Dim fso As Scripting.FileSystemObject
    
' Form load event -------------------------------------------------------------------------------------------------------------------------------

Private Sub Form_Load()
    
    On Error Resume Next
    
    bRemoteSaved = True
    
    ' Set display properties ----------------------------------------------------------------------------------------
    
    editMenu.Visible = False
    
    FRMgrid.Top = 0
    FRMgrid.Left = 0
    
    MODdbMethods.init
    MODweb.init
    
    initPreferences
    
    ' Check that remote update directory exists and create it if it doesn't. ---------------------------------------------------------------
    
    Set fso = New Scripting.FileSystemObject
    
    If Not fso.FolderExists(MODweb.sRemoteUpdateDirPath) Then fso.CreateFolder MODweb.sRemoteUpdateDirPath
    If Not fso.FolderExists(MODweb.sRemoteUpdateBackupDirPath) Then fso.CreateFolder MODweb.sRemoteUpdateBackupDirPath
    
End Sub

' Resize -------------------------------------------------------------------------------------------------------------------------

Private Sub Form_Resize()

    On Error Resume Next
    
    If ScaleWidth > 300 Then
    
        DataGrid.Width = ScaleWidth - 17
        DataGrid.Height = ScaleHeight - DataGrid.Top - 10
        
        Line1.X2 = ScaleWidth
        
    End If
            
End Sub

' Form unload ------------------------------------------------------------------------------------------------------------------

Private Sub Form_Unload(Cancel As Integer)

    On Error Resume Next
    
    removeFocusFromGrid

    If Not bRemoteSaved Then
    
        If MsgBox( _
            "You have made changes to the local database, but have not updated the remote database" & _
            vbCrLf & vbCrLf & _
            "Is this OK ?", _
            vbOKCancel, _
            "Unsaved Changes") <> 1 Then
            
            Cancel = 1
            
        End If
    End If

    If Cancel = 0 Then End
    
End Sub

' Set the widths of the dataGrid columns according to the registry preferences -----------------------------------------------------------------------------------

Public Sub setDataGridColumnWidths()

' Get preferences from registry --------------------------------------------------------------------------------
        
    strColumnWidths = getPref("", "columnWidths")
    
    ' In case there are no column widths saved --------------------------------------------------------------------
    
    If strColumnWidths = "" Then
    
        For Each fld In r.Fields
        
            strColumnWidths = strColumnWidths & "100,"
            
        Next
        
        setPref "", "columnWidths", strColumnWidths
        
    End If

    aColumnWidths = Split(strColumnWidths, ",")

    i = 0
        
' Set dataGrid column widths according to preferences in registry --------------------------------------------------------------------------

    For Each fld In FRMmain.Adodc1.Recordset.Fields
        
        FRMmain.DataGrid.Columns(i).Width = aColumnWidths(i)
            
        i = i + 1
        
    Next
    
End Sub

Private Sub editPreferences_Click()

    DLGpreferences.Show
    
End Sub

Private Sub editAddRow_Click()

    On Error GoTo errorHandler
    
    boolAddrow = True
    Adodc1.Recordset.AddNew
    
    '' SET A DEFAULT VALUE FOR ALL FIELDS
    For Each objField In Adodc1.Recordset.Fields
        objField.Value = 0
    Next
    
    uniqueID = "part_" & getUniqueTimeStamp & "_" & uniqueIDindex
    uniqueIDindex = uniqueIDindex + 1
    Adodc1.Recordset("uniqueID") = uniqueID
    isNewRecord = True
    MODweb.buildUpdateStatement Adodc1.Recordset, "INSERT"
    
    Exit Sub
    
errorHandler:

    If Err.Number = 91 Then MsgBox "There is no open DataBase"
    
    'debug.print Err.Number
End Sub

Private Sub editCopyRow_Click()
    
    On Error Resume Next
     
    copyRow
    
End Sub

Private Sub editDeleteRow_Click()

On Error GoTo errorHandler
    
    MODweb.buildUpdateStatement Adodc1.Recordset, "DELETE"
    
    FRMmain.TXTsearch.SetFocus ' this takes the focus away from the datagrid and prevents an error message from the datagrid
    
    Adodc1.Recordset.Delete

errorHandler:
    If Err.Number = 91 Then MsgBox "There are no rows to delete"
    'debug.print Err.Number
End Sub

Private Sub initPreferences()
    
    On Error Resume Next
    
    With New regOp
    
        .Root = HKEY_LOCAL_MACHINE
        .Key = "Software\bbd\AccessSearch"
        
        '======================================================================================='
        ' Install Initial Values in the registry, in case they do not exist already             '
        '======================================================================================='
        setDefaultPrefs
        
    End With
    
End Sub

'-------------------------------------------'
'   copy row from dataGrid to clipboard     '
'-------------------------------------------'
Private Sub copyRow()

On Error GoTo handleError

    Dim hasRecords As Boolean
    For Each c In DataGrid.Columns
        If c.Text <> "" Then
            hasRecords = True
            Exit For
        End If
    Next
    If hasRecords Then
        Dim rowVal As String, headers As String, i As Integer
        selVal = ""
        Dim rs As Recordset
        Set rs = FRMmain.Adodc1.Recordset
        For Each fld In rs.Fields
            headers = headers & "|" & fld.Name
        Next
        For Each c In DataGrid.Columns
            rowVal = rowVal & "|" & c.Text
            i = i + 1
        Next
        Dim objDoc As Word.Document
        Set objDoc = New Word.Document
        objDoc.Activate
        objDoc.Tables.Add objDoc.Range, 2, i
        splHeaders = Split(headers, "|")
        For i = 0 To UBound(splHeaders)
            objDoc.Tables(1).Cell(1, i + 1).Range = splHeaders(i)
        Next
        splRowVal = Split(rowVal, "|")
        For i = 0 To UBound(splRowVal)
            objDoc.Tables(1).Cell(2, i + 1).Range = splRowVal(i)
        Next
        Clipboard.Clear
        objDoc.Range.Copy
        objDoc.Close False
        Set objDoc = Nothing
    End If
    
handleError:
    'debug.print Err.Number
    If Err.Number = 7005 Then MsgBox "There are no rows to copy"
    Exit Sub
End Sub
'---------------------------------------'
'   delete a row in the dataGrid          '
'---------------------------------------'
Private Sub deleteRow()
    
    On Error Resume Next
    
    Dim deleteStr As String
    
        Dim rs As ADODB.Recordset
        Set rs = Adodc1.Recordset
        
        deleteStr = "DELETE * FROM " & Me.LISTtables.List(Me.LISTtables.ListIndex) & " WHERE [" & _
            rs.Fields(0).Name & "] = '" & rs.Fields(0).Value & "'"
         
        For i = 1 To rs.Fields.Count - 1
            deleteStr = deleteStr & " AND [" & rs.Fields(i).Name & "] = '" & rs.Fields(i).Value & "'"
        Next
        rs.Close
        Adodc1.RecordSource = deleteStr
        MsgBox deleteStr
        'rs.Open deleteStr
        'DataGrid.Refresh
handleError:
    Exit Sub
End Sub
'---------------------------------------'
'   Menu > Import click event           '
'---------------------------------------'
'Private Sub fileImport_Click()
'On Error GoTo handleError
'    CommonDialog.ShowOpen
'    With CommonDialog
'        DLGimport.Show
'        DLGimport.TEXTimportFileName.Text = .FileName
'        MODdbMethods.setImportTablesCombo .FileName
'    End With
'handleError:
'    If Err.Number = -2147217842 Then
'        DLGimport.Hide
'        Exit Sub
'    End If
'End Sub
'---------------------------------------'
'   Menu > Export Click event           '
'---------------------------------------'
Private Sub fileExportToExcel_Click()

    On Error Resume Next
        
    If LISTtables.ListIndex < 0 Then
    
        MsgBox "There is no open database to export"
        
        Exit Sub
        
    End If
        
    DLGexport.Show vbModal
  
End Sub
'---------------------------------------'
'   Menu > Open Click event             '
'---------------------------------------'
Private Sub fileOpen_Click()

On Error GoTo errorHandler
    
    With CommonDialog
        
        .Filter = "Access Databases (*.mdb)|*.mdb|All Files|*.*"
        
        .CancelError = True

        .ShowOpen
    
        MODdbMethods.openConnection .FileName
        
    End With
    
errorHandler:

    Select Case Err.Number
    
        Case 32755 ' Cancel was selected

            Exit Sub
        
    End Select
    
End Sub


Private Sub filePrint_Click()

    On Error Resume Next

    FRMgrid.GRIDresults.Clear
    FRMgrid.GRIDresults.Rows = 1
    FRMgrid.GRIDresults.Cols = 0
    intRows = 1
    intCols = 1
    On Error GoTo printErrorHandler
    Printer.Orientation = 2
    Printer.PaintPicture DataGrid.CaptureImage, 0, 0
    Printer.EndDoc
    Exit Sub
    
printErrorHandler:
    If Err.Number = 30010 Then
        MsgBox Err.Description ' "There Are No Results To Print"
    Else
        MsgBox "Error : " & Err.Description & vbCrLf & "Error Number : " & Err.Number
    End If
    Exit Sub
    
End Sub




Private Sub helpMenuAbout_Click()
    
    On Error Resume Next
    
    FRMabout.Show vbModal
    
End Sub

Private Sub searchButt_Click()

    On Error Resume Next

    If LISTtables.ListIndex > -1 Then
        
        If TXTsearch.Text <> "" Then
        
            If LISTfields.SelCount > 0 Then
            
                Dim queryStr As String
                queryStr = Trim(TXTsearch.Text)
                MODdbMethods.searchDB LISTtables.List(LISTtables.ListIndex), LISTfields.List(LISTfields.ListIndex), queryStr
            
            Else
                
                MsgBox "Choose At Least One Field To Search, or Choose ""All"""
                
            End If
        Else
        
            MsgBox "Please Choose A Phrase To Search For"
            FRMmain.TXTsearch.SetFocus
        End If
    Else
        MsgBox "No File Open"
        TXTsearch.SetFocus
    End If
    
    setDataGridColumnWidths
    
End Sub

Private Sub LISTtables_Click()

    On Error Resume Next

    If LISTtables.ListIndex > -1 Then
''''''''''''' CREATE FIELDS LIST BOX and COLUMN HEADERS FOR SEARCH RESULTS
        Dim sSelectedField As String
        
        sSelectedField = getPref("", "DefaultSearchField")
        
        MODdbMethods.setFieldsList LISTtables.List(LISTtables.ListIndex), sSelectedField
        
    End If
    
End Sub

Private Sub fileQuit_Click()

    End
    
End Sub



' Take the focus away from the last edited row so it is forced to update -------------------------------------------------------------------------

Private Sub removeFocusFromGrid()
    
    On Error Resume Next
    
    If DataGrid.Row = 0 Then
        
        DataGrid.Row = 1
    
    Else
    
        DataGrid.Row = 0
    
    End If

End Sub

' Events -------------------------------------------------------------------------------------------------------------------------

' Import File ---------------------------------------------------------------------------------------------------------------------

Public Sub fileImport_Click()

    On Error Resume Next

    With CommonDialog
    
        .Filter = "Excel Files (.xls)|*.xls|All Files|*.*"
    
        .CancelError = True
        
        .ShowOpen
        
        DLGimport.init .FileName
    
    End With

End Sub

' Web menu events ---------------------------------------------------------------------------------------------------------------

Private Sub WebDeleteSavedUpdate_Click()

    On Error Resume Next
    
    Dim fso As Scripting.FileSystemObject
    
    Set fso = New Scripting.FileSystemObject
    
    If Not fso.FileExists(MODweb.sRemoteUpdateRecordsFilePath) Then
    
        MsgBox "There are no records to delete"
    
        Exit Sub
    
    End If

    If MsgBox("Are you sure you want to delete the records ?", vbOKCancel) <> vbOK Then Exit Sub
    
    fso.CopyFile _
        MODweb.sRemoteUpdateRecordsFilePath, _
        MODweb.sRemoteUpdateBackupDirPath & "records_" & getUniqueTimeStamp
    
    fso.DeleteFile MODweb.sRemoteUpdateRecordsFilePath, False
    
    Set fso = Nothing

End Sub

Private Sub WebUpdateAllRecords_Click()
    
    On Error Resume Next
    
    removeFocusFromGrid

    updateAllRecords
    
End Sub

Private Sub WebUpdateFromFile_Click()

    On Error Resume Next

    MODweb.updateFromFile
    
End Sub

Private Sub WebUpdateLater_Click()

    On Error Resume Next
    
    removeFocusFromGrid

    MODweb.exportRecordsForUpdate

End Sub

' Tool menu events --------------------------------------------------------------------------------------------------------

Private Sub toolsCalculator_Click()
    
    On Error Resume Next
    
    Dim X As Long
    X = Shell("Calc.exe", 1)
    
End Sub

Private Sub ToolSendMail_Click()

    MODtools.sendMailToBroker
    
End Sub


Private Sub toolsPreferences_Click()

    On Error Resume Next

    DLGpreferences.Show vbModal
    
End Sub

' Data grid events ---------------------------------------------------------------------------------------------------------------

Private Sub DataGrid_AfterColEdit(ByVal ColIndex As Integer)
    
    On Error Resume Next
    
    If doRemoteUpdate Then
    
        isNewRecord = False
        MODweb.buildUpdateStatement Adodc1.Recordset, "SET"
        
    End If
    
End Sub

Private Sub DataGrid_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
    
    On Error Resume Next
    
    doRemoteUpdate = True
    Dim newValue As Variant
    
    ' Check to make sure that the user does not update the 'uniqueID' field ----------------------------------------------------------------
    ' If the condition returns true thrn cancel the update --------------------------------------------------------------------------
    
    If Adodc1.Recordset.Fields(ColIndex).Name = "uniqueID" Then
    
        Cancel = 1
        doRemoteUpdate = False
        
        Exit Sub
        
    End If
    
    MODweb.buildUpdateStatement Adodc1.Recordset, "WHERE"
    
End Sub

Private Sub DataGrid_BeforeUpdate(Cancel As Integer)
    
    On Error Resume Next
    
    Adodc1.Recordset("UPDATE") = Date & " " & Time
    
End Sub

Private Sub DataGrid_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    On Error Resume Next
    
    If Button And vbRightButton Then
    
        Dim selectedRow As Integer, Xtwips As Integer, Ytwips As Integer
        
        If Screen.TwipsPerPixelX < 1 Then Xtwips = 1 Else Xtwips = Screen.TwipsPerPixelX
        If Screen.TwipsPerPixelY < 1 Then Ytwips = 1 Else Ytwips = Screen.TwipsPerPixelY
        
        If DataGrid.ColContaining(X / Xtwips) > -1 Then

            Exit Sub

        End If
        
        selectedRow = DataGrid.RowContaining(Y / Ytwips)
        DataGrid.Row = selectedRow
        PopupMenu editMenu
        
    End If
    
End Sub

